<%
    Object isAdmin = session.getAttribute("is_admin");
    if (isAdmin == null || !(Boolean)isAdmin) {
        response.sendRedirect("login.jsp");
        return;
    }
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.model.Article" %>
<!DOCTYPE html>
<html>
<head>
    <title>题库管理</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
    <div style="color:red;">题库管理JSP已加载</div>
    <% System.out.println("quiz-admin.jsp loaded"); %>
    <div class="container mx-auto p-6">
        <h2 class="text-2xl font-bold mb-4">题库管理</h2>
        <div class="bg-white p-4 rounded shadow">
            <form method="post" class="grid grid-cols-6 gap-2 mb-4">
                <input name="question" placeholder="题目" class="col-span-2 border p-1 rounded" required>
                <input name="option_a" placeholder="A" class="border p-1 rounded" required>
                <input name="option_b" placeholder="B" class="border p-1 rounded" required>
                <input name="option_c" placeholder="C" class="border p-1 rounded" required>
                <input name="option_d" placeholder="D" class="border p-1 rounded" required>
                <input name="answer" placeholder="答案" maxlength="1" class="border p-1 rounded" required>
                <input name="explanation" placeholder="解析" class="col-span-2 border p-1 rounded">
                <button type="submit" class="col-span-2 bg-blue-500 text-white rounded px-4 py-2">添加题目</button>
            </form>
            <form action="import-quiz-sql" method="post" enctype="multipart/form-data" class="mb-4">
                <label class="block mb-2 font-medium text-gray-700">选择题库SQL文件：</label>
                <input type="file" name="quizFile" accept=".sql" required class="mb-2"/>
                <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded">一键导入题库</button>
            </form>
            <c:if test="${not empty importMsg}">
                <div class="mt-2 text-green-600">${importMsg}</div>
            </c:if>
            <c:if test="${not empty importErr}">
                <div class="mt-2 text-red-600">${importErr}</div>
            </c:if>
            <table class="min-w-full bg-white border">
                <thead>
                <tr>
                    <th class="border px-2 py-1">ID</th>
                    <th class="border px-2 py-1">题目</th>
                    <th class="border px-2 py-1">A</th>
                    <th class="border px-2 py-1">B</th>
                    <th class="border px-2 py-1">C</th>
                    <th class="border px-2 py-1">D</th>
                    <th class="border px-2 py-1">答案</th>
                    <th class="border px-2 py-1">操作</th>
                </tr>
                </thead>
                <tbody>
                <%-- 这里由Servlet输出题目列表 --%>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html> 